home *** CD-ROM | disk | FTP | other *** search
/ Hardcore Visual Basic 5.0 (2nd Edition) / Hardcore Visual Basic 5.0 - Second Edition (1997)(Microsoft Press).iso / Code / StackLst.cls < prev    next >
Text File  |  1997-06-14  |  1KB  |  49 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "CStackLst"
  6. Attribute VB_GlobalNameSpace = False
  7. Attribute VB_Creatable = True
  8. Attribute VB_PredeclaredId = False
  9. Attribute VB_Exposed = False
  10. Option Explicit
  11.  
  12. Implements IStack
  13.  
  14. Private lnkHead As CLink
  15. Private c As Long
  16.  
  17. Private Sub IStack_Push(vArg As Variant)
  18.     ' Create a temporary link with new value
  19.     Dim lnkTmp As New CLink
  20.     Set lnkTmp = New CLink
  21.     If IsObject(vArg) Then
  22.         Set lnkTmp.Item = vArg
  23.     Else
  24.         lnkTmp.Item = vArg
  25.     End If
  26.     ' Insert it at head
  27.     Set lnkTmp.NextLink = lnkHead
  28.     Set lnkHead = lnkTmp
  29.     c = c + 1
  30. End Sub
  31.  
  32. Private Function IStack_Pop() As Variant
  33.     ' Can't pop from empty list
  34.     If lnkHead Is Nothing Then Exit Function
  35.     ' Copy head value and remove the link
  36.     If IsObject(lnkHead.Item) Then
  37.         Set IStack_Pop = lnkHead.Item
  38.     Else
  39.         IStack_Pop = lnkHead.Item
  40.     End If
  41.     Set lnkHead = lnkHead.NextLink
  42.     c = c - 1
  43. End Function
  44.  
  45. Private Property Get IStack_Count() As Long
  46.     IStack_Count = c
  47. End Property
  48.  
  49.